#region Usings

using System.Collections.Generic;
using System.Xml.XPath;

#endregion

namespace Kazkommertsbank.Framework.Model.Pay
{
    public class PaymentBank
    {
        private readonly List<Payment> _results = new List<Payment>();
        private readonly string _xml;

        public PaymentBank(XPathNavigator nav)
        {
            _xml = nav.OuterXml;
            Name = nav.GetAttribute("name", "");
            XPathNavigator navigator = nav.SelectSingleNode("customer");
            if(navigator != null)
                Customer = new PaymentCustomer(navigator);

            navigator = nav.SelectSingleNode("customer_sign");
            if(navigator != null)
            {
                CustomerSign = navigator.Value;
                CustomerSignType = navigator.GetAttribute("type", "");
            }

            navigator = nav.SelectSingleNode("results");
            if(navigator != null)
                ResultsTimestamp = navigator.GetAttribute("timestamp", "");

            XPathNodeIterator nodeIterator = nav.Select("results/payment");
            while(nodeIterator.MoveNext())
            {
                if(nodeIterator.Current != null)
                    Results.Add(new Payment(nodeIterator.Current));
            }
        }

        public string ResultsTimestamp { get; private set; }
        public string Name { get; private set; }
        public PaymentCustomer Customer { get; private set; }
        public string CustomerSign { get; private set; }
        public string CustomerSignType { get; private set; }

        public List<Payment> Results
        {
            get { return _results; }
        }

        public string ToXmlString()
        {
            return _xml;
        }
    }
}